home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbplygblt.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  10.7 KB  |  406 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.58.17;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49. /* $XConsortium: mfbplygblt.c,v 5.3 89/12/06 20:24:31 keith Exp $ */
  50.  
  51. #include "X.h"
  52. #include "Xmd.h"
  53. #include "Xproto.h"
  54. #include "fontstruct.h"
  55. #include "dixfontstr.h"
  56. #include "gcstruct.h"
  57. #include "windowstr.h"
  58. #include "pixmapstr.h"
  59. #include "scrnintstr.h"
  60. #include "regionstr.h"
  61. #include "mfb.h"
  62. #include "maskbits.h"
  63. #include "miscstruct.h"
  64.  
  65. extern void QueryGlyphExtents();
  66.  
  67. /*
  68.     we should eventually special-case fixed-width fonts, although
  69. its more important for ImageText, which is meant for terminal
  70. emulators.
  71.  
  72.     this works for fonts with glyphs <= 32 bits wide.
  73.  
  74.     the clipping calculations are done for worst-case fonts.
  75. we make no assumptions about the heights, widths, or bearings
  76. of the glyphs.  if we knew that the glyphs are all the same height,
  77. we could clip the tops and bottoms per clipping box, rather
  78. than per character per clipping box.  if we knew that the glyphs'
  79. left and right bearings were well-behaved, we could clip a single
  80. character at the start, output until the last unclipped
  81. character, and then clip the last one.  this is all straightforward
  82. to determine based on max-bounds and min-bounds from the font.
  83.     there is some inefficiency introduced in the per-character
  84. clipping to make what's going on clearer.
  85.  
  86.     (it is possible, for example, for a font to be defined in which the
  87. next-to-last character in a font would be clipped out, but the last
  88. one wouldn't.  the code below deals with this.)
  89.  
  90.     PolyText looks at the fg color and the rasterop; mfbValidateGC
  91. swaps in the right routine after looking at the reduced ratserop
  92. in the private field of the GC.  
  93.  
  94.    the register allocations are provisional; in particualr startmask and
  95. endmask might not be the right things.  pglyph, xoff, pdst, and tmpSrc
  96. are fairly obvious, though.
  97.  
  98.    to avoid source proliferation, this file is compiled
  99. three times:
  100.     MFBPOLYGLYPHBLT        OPEQ
  101.     mfbPolyGlyphBltWhite    |=
  102.     mfbPolyGlyphBltBlack    &=~
  103.     mfbPolyGlyphBltInvert    ^=
  104. */
  105.  
  106. void
  107. MFBPOLYGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  108.     DrawablePtr pDrawable;
  109.     GCPtr    pGC;
  110.     int     x, y;
  111.     unsigned int nglyph;
  112.     CharInfoPtr *ppci;        /* array of character info */
  113.     unsigned char *pglyphBase;    /* start of array of glyphs */
  114. {
  115.     ExtentInfoRec info;    /* used by QueryGlyphExtents() */
  116.     BoxRec bbox;        /* string's bounding box */
  117.  
  118.     CharInfoPtr pci;
  119.     int xorg, yorg;    /* origin of drawable in bitmap */
  120.     int widthDst;    /* width of dst in longwords */
  121.  
  122.             /* these keep track of the character origin */
  123.     unsigned int *pdstBase;
  124.             /* points to longword with character origin */
  125.     int xchar;        /* xorigin of char (mod 32) */
  126.  
  127.             /* these are used for placing the glyph */
  128.     register int xoff;    /* x offset of left edge of glyph (mod 32) */
  129.     register unsigned int *pdst;
  130.             /* pointer to current longword in dst */
  131.  
  132.     int w;        /* width of glyph in bits */
  133.     int h;        /* height of glyph */
  134.     int widthGlyph;    /* width of glyph, in bytes */
  135.     register unsigned char *pglyph;
  136.             /* pointer to current row of glyph */
  137.  
  138.             /* used for putting down glyph */
  139.     register unsigned int tmpSrc;
  140.             /* for getting bits from glyph */
  141.     register int startmask;
  142.     register int endmask;
  143.     register int nFirst;/* bits of glyph in current longword */
  144.  
  145.     if (!(pGC->planemask & 1))
  146.     return;
  147.  
  148.     xorg = pDrawable->x;
  149.     yorg = pDrawable->y;
  150.     if (pDrawable->type == DRAWABLE_WINDOW)
  151.     {
  152.     pdstBase = (unsigned int *)
  153.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  154.     widthDst = (int)
  155.          (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  156.     }
  157.     else
  158.     {
  159.     pdstBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  160.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  161.     }
  162.  
  163.     x += xorg;
  164.     y += yorg;
  165.  
  166.     QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
  167.     bbox.x1 = x + info.overallLeft;
  168.     bbox.x2 = x + info.overallRight;
  169.     bbox.y1 = y - info.overallAscent;
  170.     bbox.y2 = y + info.overallDescent;
  171.  
  172.     switch ((*pGC->pScreen->RectIn)(
  173.                 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  174.     {
  175.       case rgnOUT:
  176.     break;
  177.       case rgnIN:
  178.         pdstBase = pdstBase + (widthDst * y) + (x >> 5);
  179.         xchar = x & 0x1f;
  180.  
  181.         while(nglyph--)
  182.         {
  183.         pci = *ppci;
  184.         pglyph = pglyphBase + pci->byteOffset;
  185.         w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
  186.         h = pci->metrics.ascent + pci->metrics.descent;
  187.         widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
  188.  
  189.         /* start at top scanline of glyph */
  190.         pdst = pdstBase - (pci->metrics.ascent * widthDst);
  191.  
  192.         /* find correct word in scanline and x offset within it
  193.            for left edge of glyph
  194.         */
  195.         xoff = xchar + pci->metrics.leftSideBearing;
  196.         if (xoff > 31)
  197.         {
  198.             pdst++;
  199.             xoff &= 0x1f;
  200.         }
  201.         else if (xoff < 0)
  202.         {
  203.             xoff += 32;
  204.             pdst--;
  205.         }
  206.  
  207.         if ((xoff + w) <= 32)
  208.         {
  209.             /* glyph all in one longword */
  210.             maskpartialbits(xoff, w, startmask);
  211.             while (h--)
  212.             {
  213.             getleftbits(pglyph, w, tmpSrc);
  214.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  215.             pglyph += widthGlyph;
  216.             pdst += widthDst;
  217.             }
  218.         }
  219.         else
  220.         {
  221.             /* glyph crosses longword boundary */
  222.             mask32bits(xoff, w, startmask, endmask);
  223.             nFirst = 32 - xoff;
  224.             while (h--)
  225.             {
  226.             getleftbits(pglyph, w, tmpSrc);
  227.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  228.             *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
  229.             pglyph += widthGlyph;
  230.             pdst += widthDst;
  231.             }
  232.         } /* glyph crosses longwords boundary */
  233.  
  234.         /* update character origin */
  235.         x += pci->metrics.characterWidth;
  236.         xchar += pci->metrics.characterWidth;
  237.         if (xchar > 31)
  238.         {
  239.             xchar -= 32;
  240.             pdstBase++;
  241.         }
  242.         else if (xchar < 0)
  243.         {
  244.             xchar += 32;
  245.             pdstBase--;
  246.         }
  247.         ppci++;
  248.         } /* while nglyph-- */
  249.     break;
  250.       case rgnPART:
  251.       {
  252.     TEXTPOS *ppos;
  253.     RegionPtr cclip;
  254.     int nbox;
  255.     BoxPtr pbox;
  256.     int xpos;        /* x position of char origin */
  257.     int i;
  258.     BoxRec clip;
  259.     int leftEdge, rightEdge;
  260.     int topEdge, bottomEdge;
  261.     int glyphRow;        /* first row of glyph not wholly
  262.                    clipped out */
  263.     int glyphCol;        /* leftmost visible column of glyph */
  264.     int getWidth;        /* bits to get from glyph */
  265.  
  266.     if(!(ppos = (TEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(TEXTPOS))))
  267.         return;
  268.  
  269.         pdstBase = pdstBase + (widthDst * y) + (x >> 5);
  270.         xpos = x;
  271.     xchar = xpos & 0x1f;
  272.  
  273.     for (i=0; i<nglyph; i++)
  274.     {
  275.         pci = ppci[i];
  276.  
  277.         ppos[i].xpos = xpos;
  278.         ppos[i].xchar = xchar;
  279.         ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
  280.         ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
  281.         ppos[i].topEdge = y - pci->metrics.ascent;
  282.         ppos[i].bottomEdge = y + pci->metrics.descent;
  283.         ppos[i].pdstBase = pdstBase;
  284.         ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
  285.  
  286.         xpos += pci->metrics.characterWidth;
  287.         xchar += pci->metrics.characterWidth;
  288.         if (xchar > 31)
  289.         {
  290.         xchar &= 0x1f;
  291.         pdstBase++;
  292.         }
  293.         else if (xchar < 0)
  294.         {
  295.         xchar += 32;
  296.         pdstBase--;
  297.         }
  298.     }
  299.  
  300.     cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  301.     pbox = REGION_RECTS(cclip);
  302.     nbox = REGION_NUM_RECTS(cclip);
  303.  
  304.     for (; --nbox >= 0; pbox++)
  305.     {
  306.         clip.x1 = max(bbox.x1, pbox->x1);
  307.         clip.y1 = max(bbox.y1, pbox->y1);
  308.         clip.x2 = min(bbox.x2, pbox->x2);
  309.         clip.y2 = min(bbox.y2, pbox->y2);
  310.         if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
  311.         continue;
  312.  
  313.         for(i=0; i<nglyph; i++)
  314.         {
  315.         pci = ppci[i];
  316.         xchar = ppos[i].xchar;
  317.  
  318.         /* clip the left and right edges */
  319.         if (ppos[i].leftEdge < clip.x1)
  320.             leftEdge = clip.x1;
  321.         else
  322.             leftEdge = ppos[i].leftEdge;
  323.  
  324.         if (ppos[i].rightEdge > clip.x2)
  325.             rightEdge = clip.x2;
  326.         else
  327.             rightEdge = ppos[i].rightEdge;
  328.  
  329.         w = rightEdge - leftEdge;
  330.         if (w <= 0)
  331.             continue;
  332.  
  333.         /* clip the top and bottom edges */
  334.         if (ppos[i].topEdge < clip.y1)
  335.             topEdge = clip.y1;
  336.         else
  337.             topEdge = ppos[i].topEdge;
  338.  
  339.         if (ppos[i].bottomEdge > clip.y2)
  340.             bottomEdge = clip.y2;
  341.         else
  342.             bottomEdge = ppos[i].bottomEdge;
  343.  
  344.         h = bottomEdge - topEdge;
  345.         if (h <= 0)
  346.             continue;
  347.  
  348.         glyphRow = (topEdge - y) + pci->metrics.ascent;
  349.         widthGlyph = ppos[i].widthGlyph;
  350.         pglyph = pglyphBase + pci->byteOffset;
  351.         pglyph += (glyphRow * widthGlyph);
  352.  
  353.         pdst = ppos[i].pdstBase - ((y-topEdge) * widthDst);
  354.  
  355.         glyphCol = (leftEdge - ppos[i].xpos) -
  356.                (pci->metrics.leftSideBearing);
  357.         getWidth = w + glyphCol;
  358.         xoff = xchar + (leftEdge - ppos[i].xpos);
  359.         if (xoff > 31)
  360.         {
  361.             xoff &= 0x1f;
  362.             pdst++;
  363.         }
  364.         else if (xoff < 0)
  365.         {
  366.             xoff += 32;
  367.             pdst--;
  368.         }
  369.  
  370.         if ((xoff + w) <= 32)
  371.         {
  372.             maskpartialbits(xoff, w, startmask);
  373.             while (h--)
  374.             {
  375.             getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
  376.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  377.             pglyph += widthGlyph;
  378.             pdst += widthDst;
  379.             }
  380.         }
  381.         else
  382.         {
  383.             mask32bits(xoff, w, startmask, endmask);
  384.             nFirst = 32 - xoff;
  385.             while (h--)
  386.             {
  387.             getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
  388.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  389.             *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
  390.             pglyph += widthGlyph;
  391.             pdst += widthDst;
  392.             }
  393.         }
  394.         } /* for each glyph */
  395.     } /* while nbox-- */
  396.     DEALLOCATE_LOCAL(ppos);
  397.     break;
  398.       }
  399.       default:
  400.     break;
  401.     }
  402. }
  403.  
  404.  
  405. @
  406.